//package com.jic.filecenter.controller.manager;
//
//import com.jic.common.base.vo.RestResult;
//import com.jic.filecenter.controller.errors.FileCenterErrorCode;
//import com.jic.filecenter.controller.errors.FileCenterException;
//import com.jic.filecenter.service.upload.Alioss;
//import com.jic.filecenter.service.upload.FileUploadService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.IOException;
//
//@RestController
//@RequestMapping("/api")
//@Slf4j
//public class FileUploadController {
//    @Autowired
//    private FileUploadService fileUPloadService;
//
//    @Autowired
//    private Alioss alioss;
//
//    @PostMapping("/upload")
//    public RestResult uploadFile(@RequestParam("file") MultipartFile file,
//                                 @RequestParam(value = "type",required = false) String type) throws Throwable{
//
//        log.debug("uploading file size: " + String.valueOf(file.getSize()) + " type: " + file.getContentType());
//        RestResult<String> restResult = fileUPloadService.fileUpload(file,type);
//        return restResult;
//
//    }
//
//    @PostMapping("/ali/upload")
//    public RestResult<String> aliUpaload(@RequestParam("file") MultipartFile file,
//                                 @RequestParam(value = "type",required = false) String type){
//
//        log.debug("uploading file size: " + String.valueOf(file.getSize()) + " type: " + file.getContentType());
//        if(file.getSize() < 10240||file.getSize() > 204800){
//            return RestResult.error("9999", "文件大小范围10KB至200KB");
//        }
//        String resourceFilename = file.getOriginalFilename();
//        String suffix = resourceFilename.substring(resourceFilename.lastIndexOf("."),resourceFilename.length());
//        if(!suffix.equals(".jpg") && !suffix.equals(".jpeg") && !suffix.equals(".bmp") && !suffix.equals(".png")){
//            return RestResult.error("9999", "不支持的文件格式");
//        }
//        try {
//            String url = alioss.filelUpload(file,type);
//            return RestResult.success(url);
//        } catch (IOException e) {
//            log.error("File Upload Fail",e);
//            return RestResult.error("9999","文件上传失败");
//        }
//
//    }
//}
